﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace AbpDevelopmentLog.Migrations
{
    public partial class Initial_Migrations : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "abcd_ApplicationLanguages",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    Name = table.Column<string>(maxLength: 128, nullable: false),
                    DisplayName = table.Column<string>(maxLength: 64, nullable: false),
                    Icon = table.Column<string>(maxLength: 128, nullable: true),
                    IsDisabled = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_ApplicationLanguages", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "abcd_ApplicationLanguageTexts",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    LanguageName = table.Column<string>(maxLength: 128, nullable: false),
                    Source = table.Column<string>(maxLength: 128, nullable: false),
                    Key = table.Column<string>(maxLength: 190, nullable: false),
                    Value = table.Column<string>(maxLength: 67108864, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_ApplicationLanguageTexts", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "abcd_AuditLogs",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    ExecutionTime = table.Column<DateTime>(nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: true),
                    ServiceName = table.Column<string>(maxLength: 256, nullable: true),
                    MethodName = table.Column<string>(maxLength: 256, nullable: true),
                    Parameters = table.Column<string>(maxLength: 1024, nullable: true),
                    ReturnValue = table.Column<string>(nullable: true),
                    ExecutionDuration = table.Column<int>(nullable: false),
                    ClientIpAddress = table.Column<string>(maxLength: 64, nullable: true),
                    ClientName = table.Column<string>(maxLength: 128, nullable: true),
                    BrowserInfo = table.Column<string>(maxLength: 512, nullable: true),
                    Exception = table.Column<string>(maxLength: 2000, nullable: true),
                    ImpersonatorUserId = table.Column<long>(nullable: true),
                    ImpersonatorTenantId = table.Column<int>(nullable: true),
                    CustomData = table.Column<string>(maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_AuditLogs", x => new { x.Id, x.ExecutionTime });
                });

            migrationBuilder.CreateTable(
                name: "abcd_BackgroundJobInfos",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    JobType = table.Column<string>(maxLength: 512, nullable: false),
                    JobArgs = table.Column<string>(maxLength: 1048576, nullable: false),
                    TryCount = table.Column<short>(nullable: false),
                    NextTryTime = table.Column<DateTime>(nullable: false),
                    LastTryTime = table.Column<DateTime>(nullable: true),
                    IsAbandoned = table.Column<bool>(nullable: false),
                    Priority = table.Column<byte>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_BackgroundJobInfos", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "abcd_Editions",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    Name = table.Column<string>(maxLength: 32, nullable: false),
                    DisplayName = table.Column<string>(maxLength: 64, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_Editions", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "abcd_EntityChangeSets",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    BrowserInfo = table.Column<string>(maxLength: 512, nullable: true),
                    ClientIpAddress = table.Column<string>(maxLength: 64, nullable: true),
                    ClientName = table.Column<string>(maxLength: 128, nullable: true),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    ExtensionData = table.Column<string>(nullable: true),
                    ImpersonatorTenantId = table.Column<int>(nullable: true),
                    ImpersonatorUserId = table.Column<long>(nullable: true),
                    Reason = table.Column<string>(maxLength: 190, nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_EntityChangeSets", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "abcd_NotificationInfos",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    NotificationName = table.Column<string>(maxLength: 96, nullable: false),
                    Data = table.Column<string>(maxLength: 1048576, nullable: true),
                    DataTypeName = table.Column<string>(maxLength: 512, nullable: true),
                    EntityTypeName = table.Column<string>(maxLength: 250, nullable: true),
                    EntityTypeAssemblyQualifiedName = table.Column<string>(maxLength: 512, nullable: true),
                    EntityId = table.Column<string>(maxLength: 96, nullable: true),
                    Severity = table.Column<byte>(nullable: false),
                    UserIds = table.Column<string>(maxLength: 131072, nullable: true),
                    ExcludedUserIds = table.Column<string>(maxLength: 131072, nullable: true),
                    TenantIds = table.Column<string>(maxLength: 131072, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_NotificationInfos", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "abcd_NotificationSubscriptionInfos",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    NotificationName = table.Column<string>(maxLength: 96, nullable: true),
                    EntityTypeName = table.Column<string>(maxLength: 190, nullable: true),
                    EntityTypeAssemblyQualifiedName = table.Column<string>(maxLength: 512, nullable: true),
                    EntityId = table.Column<string>(maxLength: 96, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_NotificationSubscriptionInfos", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "abcd_OrganizationUnitRoles",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    RoleId = table.Column<int>(nullable: false),
                    OrganizationUnitId = table.Column<long>(nullable: false),
                    IsDeleted = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_OrganizationUnitRoles", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "abcd_OrganizationUnits",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    ParentId = table.Column<long>(nullable: true),
                    Code = table.Column<string>(maxLength: 95, nullable: false),
                    DisplayName = table.Column<string>(type: "VARCHAR(128) COLLATE gbk_chinese_ci", maxLength: 128, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_OrganizationUnits", x => x.Id);
                    table.ForeignKey(
                        name: "FK_abcd_OrganizationUnits_abcd_OrganizationUnits_ParentId",
                        column: x => x.ParentId,
                        principalTable: "abcd_OrganizationUnits",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "abcd_TenantNotificationInfos",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    NotificationName = table.Column<string>(maxLength: 96, nullable: false),
                    Data = table.Column<string>(maxLength: 1048576, nullable: true),
                    DataTypeName = table.Column<string>(maxLength: 512, nullable: true),
                    EntityTypeName = table.Column<string>(maxLength: 250, nullable: true),
                    EntityTypeAssemblyQualifiedName = table.Column<string>(maxLength: 512, nullable: true),
                    EntityId = table.Column<string>(maxLength: 96, nullable: true),
                    Severity = table.Column<byte>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_TenantNotificationInfos", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "abcd_UserAccounts",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    UserLinkId = table.Column<long>(nullable: true),
                    UserName = table.Column<string>(maxLength: 190, nullable: true),
                    EmailAddress = table.Column<string>(maxLength: 190, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_UserAccounts", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "abcd_UserLoginAttempts",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    TenantId = table.Column<int>(nullable: true),
                    TenancyName = table.Column<string>(maxLength: 64, nullable: true),
                    UserId = table.Column<long>(nullable: true),
                    UserNameOrEmailAddress = table.Column<string>(maxLength: 190, nullable: true),
                    ClientIpAddress = table.Column<string>(maxLength: 64, nullable: true),
                    ClientName = table.Column<string>(maxLength: 128, nullable: true),
                    BrowserInfo = table.Column<string>(maxLength: 512, nullable: true),
                    Result = table.Column<byte>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_UserLoginAttempts", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "abcd_UserNotificationInfos",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    TenantNotificationId = table.Column<Guid>(nullable: false),
                    State = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_UserNotificationInfos", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "abcd_UserOrganizationUnits",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    OrganizationUnitId = table.Column<long>(nullable: false),
                    IsDeleted = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_UserOrganizationUnits", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "abcd_Users",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    AuthenticationSource = table.Column<string>(maxLength: 64, nullable: true),
                    UserName = table.Column<string>(maxLength: 190, nullable: false),
                    TenantId = table.Column<int>(nullable: true),
                    EmailAddress = table.Column<string>(maxLength: 190, nullable: false),
                    Name = table.Column<string>(type: "VARCHAR(64) COLLATE gbk_chinese_ci", maxLength: 64, nullable: false),
                    Surname = table.Column<string>(type: "VARCHAR(64) COLLATE gbk_chinese_ci", maxLength: 64, nullable: false),
                    Password = table.Column<string>(maxLength: 128, nullable: false),
                    EmailConfirmationCode = table.Column<string>(maxLength: 328, nullable: true),
                    PasswordResetCode = table.Column<string>(maxLength: 328, nullable: true),
                    LockoutEndDateUtc = table.Column<DateTime>(nullable: true),
                    AccessFailedCount = table.Column<int>(nullable: false),
                    IsLockoutEnabled = table.Column<bool>(nullable: false),
                    PhoneNumber = table.Column<string>(maxLength: 32, nullable: true),
                    IsPhoneNumberConfirmed = table.Column<bool>(nullable: false),
                    SecurityStamp = table.Column<string>(maxLength: 128, nullable: true),
                    IsTwoFactorEnabled = table.Column<bool>(nullable: false),
                    IsEmailConfirmed = table.Column<bool>(nullable: false),
                    IsActive = table.Column<bool>(nullable: false),
                    NormalizedUserName = table.Column<string>(maxLength: 190, nullable: false),
                    NormalizedEmailAddress = table.Column<string>(maxLength: 190, nullable: false),
                    ConcurrencyStamp = table.Column<string>(maxLength: 128, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_Users", x => x.Id);
                    table.ForeignKey(
                        name: "FK_abcd_Users_abcd_Users_CreatorUserId",
                        column: x => x.CreatorUserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_abcd_Users_abcd_Users_DeleterUserId",
                        column: x => x.DeleterUserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_abcd_Users_abcd_Users_LastModifierUserId",
                        column: x => x.LastModifierUserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "abcd_FeatureSettings",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    Name = table.Column<string>(maxLength: 128, nullable: false),
                    Value = table.Column<string>(maxLength: 2000, nullable: false),
                    Discriminator = table.Column<string>(nullable: false),
                    EditionId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_FeatureSettings", x => x.Id);
                    table.ForeignKey(
                        name: "FK_abcd_FeatureSettings_abcd_Editions_EditionId",
                        column: x => x.EditionId,
                        principalTable: "abcd_Editions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "abcd_EntityChanges",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    ChangeTime = table.Column<DateTime>(nullable: false),
                    ChangeType = table.Column<byte>(nullable: false),
                    EntityChangeSetId = table.Column<long>(nullable: false),
                    EntityId = table.Column<string>(maxLength: 48, nullable: true),
                    EntityTypeFullName = table.Column<string>(maxLength: 190, nullable: true),
                    TenantId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_EntityChanges", x => x.Id);
                    table.ForeignKey(
                        name: "FK_abcd_EntityChanges_abcd_EntityChangeSets_EntityChangeSetId",
                        column: x => x.EntityChangeSetId,
                        principalTable: "abcd_EntityChangeSets",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "abcd_Roles",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    Name = table.Column<string>(maxLength: 32, nullable: false),
                    DisplayName = table.Column<string>(maxLength: 64, nullable: false),
                    IsStatic = table.Column<bool>(nullable: false),
                    IsDefault = table.Column<bool>(nullable: false),
                    NormalizedName = table.Column<string>(maxLength: 32, nullable: false),
                    ConcurrencyStamp = table.Column<string>(maxLength: 128, nullable: true),
                    Description = table.Column<string>(maxLength: 5000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_Roles", x => x.Id);
                    table.ForeignKey(
                        name: "FK_abcd_Roles_abcd_Users_CreatorUserId",
                        column: x => x.CreatorUserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_abcd_Roles_abcd_Users_DeleterUserId",
                        column: x => x.DeleterUserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_abcd_Roles_abcd_Users_LastModifierUserId",
                        column: x => x.LastModifierUserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "abcd_Settings",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: true),
                    Name = table.Column<string>(maxLength: 190, nullable: false),
                    Value = table.Column<string>(maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_Settings", x => x.Id);
                    table.ForeignKey(
                        name: "FK_abcd_Settings_abcd_Users_UserId",
                        column: x => x.UserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "abcd_Tenants",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    TenancyName = table.Column<string>(maxLength: 64, nullable: false),
                    Name = table.Column<string>(maxLength: 128, nullable: false),
                    ConnectionString = table.Column<string>(maxLength: 1024, nullable: true),
                    IsActive = table.Column<bool>(nullable: false),
                    EditionId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_Tenants", x => x.Id);
                    table.ForeignKey(
                        name: "FK_abcd_Tenants_abcd_Users_CreatorUserId",
                        column: x => x.CreatorUserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_abcd_Tenants_abcd_Users_DeleterUserId",
                        column: x => x.DeleterUserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_abcd_Tenants_abcd_Editions_EditionId",
                        column: x => x.EditionId,
                        principalTable: "abcd_Editions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_abcd_Tenants_abcd_Users_LastModifierUserId",
                        column: x => x.LastModifierUserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "abcd_UserClaims",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    ClaimType = table.Column<string>(maxLength: 190, nullable: true),
                    ClaimValue = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_UserClaims", x => x.Id);
                    table.ForeignKey(
                        name: "FK_abcd_UserClaims_abcd_Users_UserId",
                        column: x => x.UserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "abcd_UserLogins",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    LoginProvider = table.Column<string>(maxLength: 128, nullable: false),
                    ProviderKey = table.Column<string>(maxLength: 190, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_UserLogins", x => x.Id);
                    table.ForeignKey(
                        name: "FK_abcd_UserLogins_abcd_Users_UserId",
                        column: x => x.UserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "abcd_UserRoles",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    RoleId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_UserRoles", x => x.Id);
                    table.ForeignKey(
                        name: "FK_abcd_UserRoles_abcd_Users_UserId",
                        column: x => x.UserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "abcd_UserTokens",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    TenantId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: false),
                    LoginProvider = table.Column<string>(maxLength: 128, nullable: true),
                    Name = table.Column<string>(maxLength: 128, nullable: true),
                    Value = table.Column<string>(maxLength: 512, nullable: true),
                    ExpireDate = table.Column<DateTime>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_UserTokens", x => x.Id);
                    table.ForeignKey(
                        name: "FK_abcd_UserTokens_abcd_Users_UserId",
                        column: x => x.UserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "abcd_EntityPropertyChanges",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    EntityChangeId = table.Column<long>(nullable: false),
                    NewValue = table.Column<string>(maxLength: 512, nullable: true),
                    OriginalValue = table.Column<string>(maxLength: 512, nullable: true),
                    PropertyName = table.Column<string>(maxLength: 96, nullable: true),
                    PropertyTypeFullName = table.Column<string>(maxLength: 192, nullable: true),
                    TenantId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_EntityPropertyChanges", x => x.Id);
                    table.ForeignKey(
                        name: "FK_abcd_EntityPropertyChanges_abcd_EntityChanges_EntityChangeId",
                        column: x => x.EntityChangeId,
                        principalTable: "abcd_EntityChanges",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "abcd_PermissionSettings",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    Name = table.Column<string>(maxLength: 128, nullable: false),
                    IsGranted = table.Column<bool>(nullable: false),
                    Discriminator = table.Column<string>(nullable: false),
                    RoleId = table.Column<int>(nullable: true),
                    UserId = table.Column<long>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_PermissionSettings", x => x.Id);
                    table.ForeignKey(
                        name: "FK_abcd_PermissionSettings_abcd_Roles_RoleId",
                        column: x => x.RoleId,
                        principalTable: "abcd_Roles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_abcd_PermissionSettings_abcd_Users_UserId",
                        column: x => x.UserId,
                        principalTable: "abcd_Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "abcd_RoleClaims",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    TenantId = table.Column<int>(nullable: true),
                    RoleId = table.Column<int>(nullable: false),
                    ClaimType = table.Column<string>(maxLength: 190, nullable: true),
                    ClaimValue = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_abcd_RoleClaims", x => x.Id);
                    table.ForeignKey(
                        name: "FK_abcd_RoleClaims_abcd_Roles_RoleId",
                        column: x => x.RoleId,
                        principalTable: "abcd_Roles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_ApplicationLanguages_TenantId_Name",
                table: "abcd_ApplicationLanguages",
                columns: new[] { "TenantId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_ApplicationLanguageTexts_TenantId_Source_LanguageName_K~",
                table: "abcd_ApplicationLanguageTexts",
                columns: new[] { "TenantId", "Source", "LanguageName", "Key" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_AuditLogs_TenantId_ExecutionDuration",
                table: "abcd_AuditLogs",
                columns: new[] { "TenantId", "ExecutionDuration" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_AuditLogs_TenantId_ExecutionTime",
                table: "abcd_AuditLogs",
                columns: new[] { "TenantId", "ExecutionTime" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_AuditLogs_TenantId_UserId",
                table: "abcd_AuditLogs",
                columns: new[] { "TenantId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_BackgroundJobInfos_IsAbandoned_NextTryTime",
                table: "abcd_BackgroundJobInfos",
                columns: new[] { "IsAbandoned", "NextTryTime" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_EntityChanges_EntityChangeSetId",
                table: "abcd_EntityChanges",
                column: "EntityChangeSetId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_EntityChanges_EntityTypeFullName_EntityId",
                table: "abcd_EntityChanges",
                columns: new[] { "EntityTypeFullName", "EntityId" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_EntityChangeSets_TenantId_CreationTime",
                table: "abcd_EntityChangeSets",
                columns: new[] { "TenantId", "CreationTime" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_EntityChangeSets_TenantId_Reason",
                table: "abcd_EntityChangeSets",
                columns: new[] { "TenantId", "Reason" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_EntityChangeSets_TenantId_UserId",
                table: "abcd_EntityChangeSets",
                columns: new[] { "TenantId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_EntityPropertyChanges_EntityChangeId",
                table: "abcd_EntityPropertyChanges",
                column: "EntityChangeId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_FeatureSettings_EditionId_Name",
                table: "abcd_FeatureSettings",
                columns: new[] { "EditionId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_FeatureSettings_TenantId_Name",
                table: "abcd_FeatureSettings",
                columns: new[] { "TenantId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_NotificationSubscriptionInfos_NotificationName_EntityTy~",
                table: "abcd_NotificationSubscriptionInfos",
                columns: new[] { "NotificationName", "EntityTypeName", "EntityId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_NotificationSubscriptionInfos_TenantId_NotificationName~",
                table: "abcd_NotificationSubscriptionInfos",
                columns: new[] { "TenantId", "NotificationName", "EntityTypeName", "EntityId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_OrganizationUnitRoles_TenantId_OrganizationUnitId",
                table: "abcd_OrganizationUnitRoles",
                columns: new[] { "TenantId", "OrganizationUnitId" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_OrganizationUnitRoles_TenantId_RoleId",
                table: "abcd_OrganizationUnitRoles",
                columns: new[] { "TenantId", "RoleId" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_OrganizationUnits_ParentId",
                table: "abcd_OrganizationUnits",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_OrganizationUnits_TenantId_Code",
                table: "abcd_OrganizationUnits",
                columns: new[] { "TenantId", "Code" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_PermissionSettings_TenantId_Name",
                table: "abcd_PermissionSettings",
                columns: new[] { "TenantId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_PermissionSettings_RoleId",
                table: "abcd_PermissionSettings",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_PermissionSettings_UserId",
                table: "abcd_PermissionSettings",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_RoleClaims_RoleId",
                table: "abcd_RoleClaims",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_RoleClaims_TenantId_ClaimType",
                table: "abcd_RoleClaims",
                columns: new[] { "TenantId", "ClaimType" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Roles_CreatorUserId",
                table: "abcd_Roles",
                column: "CreatorUserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Roles_DeleterUserId",
                table: "abcd_Roles",
                column: "DeleterUserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Roles_LastModifierUserId",
                table: "abcd_Roles",
                column: "LastModifierUserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Roles_TenantId_NormalizedName",
                table: "abcd_Roles",
                columns: new[] { "TenantId", "NormalizedName" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Settings_UserId",
                table: "abcd_Settings",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Settings_TenantId_Name_UserId",
                table: "abcd_Settings",
                columns: new[] { "TenantId", "Name", "UserId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_abcd_TenantNotificationInfos_TenantId",
                table: "abcd_TenantNotificationInfos",
                column: "TenantId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Tenants_CreatorUserId",
                table: "abcd_Tenants",
                column: "CreatorUserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Tenants_DeleterUserId",
                table: "abcd_Tenants",
                column: "DeleterUserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Tenants_EditionId",
                table: "abcd_Tenants",
                column: "EditionId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Tenants_LastModifierUserId",
                table: "abcd_Tenants",
                column: "LastModifierUserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Tenants_TenancyName",
                table: "abcd_Tenants",
                column: "TenancyName");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserAccounts_EmailAddress",
                table: "abcd_UserAccounts",
                column: "EmailAddress");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserAccounts_UserName",
                table: "abcd_UserAccounts",
                column: "UserName");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserAccounts_TenantId_EmailAddress",
                table: "abcd_UserAccounts",
                columns: new[] { "TenantId", "EmailAddress" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserAccounts_TenantId_UserId",
                table: "abcd_UserAccounts",
                columns: new[] { "TenantId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserAccounts_TenantId_UserName",
                table: "abcd_UserAccounts",
                columns: new[] { "TenantId", "UserName" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserClaims_UserId",
                table: "abcd_UserClaims",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserClaims_TenantId_ClaimType",
                table: "abcd_UserClaims",
                columns: new[] { "TenantId", "ClaimType" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserLoginAttempts_UserId_TenantId",
                table: "abcd_UserLoginAttempts",
                columns: new[] { "UserId", "TenantId" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserLoginAttempts_TenancyName_UserNameOrEmailAddress_Re~",
                table: "abcd_UserLoginAttempts",
                columns: new[] { "TenancyName", "UserNameOrEmailAddress", "Result" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserLogins_UserId",
                table: "abcd_UserLogins",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserLogins_TenantId_UserId",
                table: "abcd_UserLogins",
                columns: new[] { "TenantId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserLogins_TenantId_LoginProvider_ProviderKey",
                table: "abcd_UserLogins",
                columns: new[] { "TenantId", "LoginProvider", "ProviderKey" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserNotificationInfos_UserId_State_CreationTime",
                table: "abcd_UserNotificationInfos",
                columns: new[] { "UserId", "State", "CreationTime" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserOrganizationUnits_TenantId_OrganizationUnitId",
                table: "abcd_UserOrganizationUnits",
                columns: new[] { "TenantId", "OrganizationUnitId" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserOrganizationUnits_TenantId_UserId",
                table: "abcd_UserOrganizationUnits",
                columns: new[] { "TenantId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserRoles_UserId",
                table: "abcd_UserRoles",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserRoles_TenantId_RoleId",
                table: "abcd_UserRoles",
                columns: new[] { "TenantId", "RoleId" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserRoles_TenantId_UserId",
                table: "abcd_UserRoles",
                columns: new[] { "TenantId", "UserId" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Users_CreatorUserId",
                table: "abcd_Users",
                column: "CreatorUserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Users_DeleterUserId",
                table: "abcd_Users",
                column: "DeleterUserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Users_LastModifierUserId",
                table: "abcd_Users",
                column: "LastModifierUserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Users_TenantId_NormalizedEmailAddress",
                table: "abcd_Users",
                columns: new[] { "TenantId", "NormalizedEmailAddress" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_Users_TenantId_NormalizedUserName",
                table: "abcd_Users",
                columns: new[] { "TenantId", "NormalizedUserName" });

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserTokens_UserId",
                table: "abcd_UserTokens",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_abcd_UserTokens_TenantId_UserId",
                table: "abcd_UserTokens",
                columns: new[] { "TenantId", "UserId" });
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "abcd_ApplicationLanguages");

            migrationBuilder.DropTable(
                name: "abcd_ApplicationLanguageTexts");

            migrationBuilder.DropTable(
                name: "abcd_AuditLogs");

            migrationBuilder.DropTable(
                name: "abcd_BackgroundJobInfos");

            migrationBuilder.DropTable(
                name: "abcd_EntityPropertyChanges");

            migrationBuilder.DropTable(
                name: "abcd_FeatureSettings");

            migrationBuilder.DropTable(
                name: "abcd_NotificationInfos");

            migrationBuilder.DropTable(
                name: "abcd_NotificationSubscriptionInfos");

            migrationBuilder.DropTable(
                name: "abcd_OrganizationUnitRoles");

            migrationBuilder.DropTable(
                name: "abcd_OrganizationUnits");

            migrationBuilder.DropTable(
                name: "abcd_PermissionSettings");

            migrationBuilder.DropTable(
                name: "abcd_RoleClaims");

            migrationBuilder.DropTable(
                name: "abcd_Settings");

            migrationBuilder.DropTable(
                name: "abcd_TenantNotificationInfos");

            migrationBuilder.DropTable(
                name: "abcd_Tenants");

            migrationBuilder.DropTable(
                name: "abcd_UserAccounts");

            migrationBuilder.DropTable(
                name: "abcd_UserClaims");

            migrationBuilder.DropTable(
                name: "abcd_UserLoginAttempts");

            migrationBuilder.DropTable(
                name: "abcd_UserLogins");

            migrationBuilder.DropTable(
                name: "abcd_UserNotificationInfos");

            migrationBuilder.DropTable(
                name: "abcd_UserOrganizationUnits");

            migrationBuilder.DropTable(
                name: "abcd_UserRoles");

            migrationBuilder.DropTable(
                name: "abcd_UserTokens");

            migrationBuilder.DropTable(
                name: "abcd_EntityChanges");

            migrationBuilder.DropTable(
                name: "abcd_Roles");

            migrationBuilder.DropTable(
                name: "abcd_Editions");

            migrationBuilder.DropTable(
                name: "abcd_EntityChangeSets");

            migrationBuilder.DropTable(
                name: "abcd_Users");
        }
    }
}
